package com.farm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 页面标题
                .title("田园-后端API接口文档")

                // 联系方式
                .contact(
                        new Contact(
                                "田园触手可及",
                                "https://gitee.com/ctidy/Farm",
                                "CTidy@foxmail.com"
                        )
                )

                // 描述
                .description("欢迎访问田园接口文档")

                // 版本号
                .version("0.0.1")

                .build();
    }


    @Bean("安全模块")
    public Docket shiroAPIs() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("安全模块")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.farm.controller.shiro"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean("农场模块")
    public Docket farmAPIs() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("农场模块")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.farm.controller.farm"))
                .paths(PathSelectors.any())
                .build();
    }

}
